package org.zcl.sharding.service.impl;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import org.zcl.sharding.entity.User;
import org.zcl.sharding.mapper.UserMapper;
import org.zcl.sharding.service.UserService;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * (TbUser0)表服务实现类
 *
 * @author makejava
 * @since 2024-07-03 15:31:09
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    public String getUsers() {
        List<User> users = userMapper.getUsers();
        return JSON.toJSONString(users);
    }

    public String addUsers() {
        for (int i = 10; i < 20; i++) {
            User user = new User();
            user.setId(i + 1);
            user.setUsername("zhangsan" + i);
            user.setPassword("123456");
            user.setCreateTime(LocalDateTime.now());
            user.setUpdateTime(LocalDateTime.now());
            user.setUserStatus(1);
            userMapper.addUser(user);
        }
        for (int i = 10; i < 20; i++) {
            User user = new User();
            user.setId(i + 1);
            user.setUsername("zhangsan" + i);
            user.setPassword("123456");
            user.setCreateTime(LocalDateTime.now());
            user.setUpdateTime(LocalDateTime.now());
            user.setUserStatus(2);
            userMapper.addUser(user);
        }
        return "success";
    }
}
